package com.wdciti.sccp.iot.tsdata.impl.iotdb;

import com.wdciti.sccp.iot.tsdata.core.api.TSDBWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.iotdb.session.pool.SessionPool;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Before;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PreDestroy;


/**
 * @author JINWEN
 */
@Slf4j
@Configuration()
public class TsDataAutoConfiguration {

//    @Bean
//    public IotDbSessionConfig iotDbSessionConfig() {
//        return new IotDbSessionConfig();
//    }


    @Bean
    public TSDBWrapper<SessionPool> iotdbSession(IotDbSessionConfig config) {
        SessionPool sessionPool = new SessionPool.Builder()
                .host(config.getHost())
                .port(config.getPort())
                .user(config.getUsername())
                .password(config.getPassword())
                .maxSize(config.getMaxSize())
                .build();
        log.info("Initializing [IotDB] SessionPool: host={},port={},user={},maxSize={}",
                config.getHost(), config.getPort(), config.getUsername(), config.getMaxSize());
        return new IotdbWrapper(sessionPool);
    }


}
